package com.example.xm.adapter.HomeAdapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.constraintlayout.widget.ConstraintLayout;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.example.xm.R;
import com.example.xm.base.BaseAdapter;
import com.example.xm.bean.HomeBean.HomeTopicDiscussedBean;
import com.example.xm.utiles.SystemUtils;

import java.util.List;

public class TopicDiscusseAdapter extends BaseAdapter {
    public TopicDiscusseAdapter(Context context, List data) {
        super(context, data);
    }

    @Override
    protected int getLayout() {
        return R.layout.layout_topic_item;
    }

    @Override
    protected void bindData(BaseViewHolder viewHolder, Object o) {
        ConstraintLayout layout_item = (ConstraintLayout) viewHolder.getViewById(R.id.layout_item);
        ImageView img = (ImageView) viewHolder.getViewById(R.id.img_head);
        TextView nickname = (TextView) viewHolder.getViewById(R.id.txt_nickname);
        TextView users = (TextView) viewHolder.getViewById(R.id.txt_users);
        View viewById = viewHolder.getViewById(R.id.txt_activity);
        HomeTopicDiscussedBean.DataBean dataBean = (HomeTopicDiscussedBean.DataBean) o;
        if (dataBean.getType() == 1) {
            layout_item.setBackgroundResource(R.drawable.round_1);
        } else {
            layout_item.setBackgroundResource(R.drawable.round_2);
        }
        //设置头像的圆角
        int round = SystemUtils.px2Dp(context, 60);
        RoundedCorners roundedCorners = new RoundedCorners(round);
        RequestOptions requestOptions = RequestOptions.bitmapTransform(roundedCorners);
        Glide.with(context).load(dataBean.getImageUrl()).apply(requestOptions).into(img);
        if (!TextUtils.isEmpty(dataBean.getName())) {
            nickname.setText(dataBean.getName());
        }
        users.setText(dataBean.getAttentionNum() + "人参与");
    }
}
